package com.proxy.common.pool.common;

/**
 * 连接池配置对象
 * <p>
 * Created by liufish on 17/1/27.
 */
public class PoolConfig {


    /**
     * 最大活跃值
     */
    int maxActive = 8;

    /**
     * 初始化值
     */
    int initial = 0;

    /**
     * 最小活跃值
     */
    int minActive = initial;

    /**
     * 最大等待时间,单位为毫秒
     */
    long maxWaitMillisOnBorrow = 500;

    /**
     * 取出验证
     */
    boolean testOnBorrow = false;

    /**
     * 连接超时
     */
    int connectionTimeout;

    /**
     * 回收时验证
     */
    boolean testOnReturn = false;

    /**
     * 回收空闲验证
     */
    boolean testWhileIdle = false;

    /**
     * 回收间隔时间点
     */
    long timeBetweenEvictionRunsMillis;

    /**
     * 在队列里面的最小空闲周期
     * 如果空闲队列里面的值大于初始化的值,且最小借出时间大于这个生存周期。
     */
    long timeAliveIdleMillis = 30 * 60 * 1000;

    public void validatePropCorrelation() {

        if (maxActive < initial){
            throw new PoolException( "maxActive < initial");
        }

        if (maxActive < minActive){
            throw new PoolException("maxActive < minActive");
        }

        if (initial < minActive){
            throw new PoolException("initial < minActive");
        }
        if (timeAliveIdleMillis < timeBetweenEvictionRunsMillis){
            throw new PoolException("timeAliveIdleMillis < timeBetweenEvictionRunsMillis");
        }

    }

    public long getTimeAliveIdleMillis() {
        return timeAliveIdleMillis;
    }

    public void setTimeAliveIdleMillis(long timeAliveIdleMillis) {
        this.timeAliveIdleMillis = timeAliveIdleMillis;
    }

    public int getMaxActive() {
        return maxActive;
    }

    public void setMaxActive(int maxActive) {
        this.maxActive = maxActive;
    }

    public int getInitial() {
        return initial;
    }

    public void setInitial(int initial) {
        this.initial = initial;
    }

    public long getMaxWaitMillisOnBorrow() {
        return maxWaitMillisOnBorrow;
    }

    public void setMaxWaitMillisOnBorrow(long maxWaitMillisOnBorrow) {
        this.maxWaitMillisOnBorrow = maxWaitMillisOnBorrow;
    }

    public boolean isTestOnBorrow() {
        return testOnBorrow;
    }

    public void setTestOnBorrow(boolean testOnBorrow) {
        this.testOnBorrow = testOnBorrow;
    }

    public boolean isTestOnReturn() {
        return testOnReturn;
    }

    public void setTestOnReturn(boolean testOnReturn) {
        this.testOnReturn = testOnReturn;
    }

    public boolean isTestWhileIdle() {
        return testWhileIdle;
    }

    public void setTestWhileIdle(boolean testWhileIdle) {
        this.testWhileIdle = testWhileIdle;
    }

    public int getMinActive() {
        return minActive;
    }

    public void setMinActive(int minActive) {
        this.minActive = minActive;
    }

    public long getTimeBetweenEvictionRunsMillis() {
        return timeBetweenEvictionRunsMillis;
    }

    public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
        this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
    }

    public int getConnectionTimeout() {
        return connectionTimeout;
    }

    public void setConnectionTimeout(int connectionTimeout) {
        this.connectionTimeout = connectionTimeout;
    }


}
